/**
 * <p>Title: Ellipse</p>
 * Description: CS 235 Assignment 2 
 * 	    Contains the methods to create Ellipse and calculates the area, and circumference of an ellipse with a  major and minor axes
 * @author JGroup 7: Nicholas A. Peterson, Dan Prayfrock, Tyler Rasmussen, John Feia
 * @date   Nov 4th 2011
 */
package a2;

/**
 * An ellipse with integer dimensions.
 * 
 */
public class Ellipse {
	// Private components:
	private int major_axis;																						//Variable Major Axes
	private int minor_axis;																						//Variable Minor Axes

	

	/**
	 * Create a new Ellipse with the specified major and minor axes.
	 * The axes must be non-negative.
	 
	 */
	// Constructors:
	public Ellipse(int maj, int min) {
		this.major_axis = maj;																					//Major = Ellipse(int maj, x)
		this.minor_axis = min;																					//Minor = Ellipse(x, int min
	}

	

	/**
	 * The major axis or length of this ellipse.
	 */
	// Queries:
	public int majorAxis() {
		return major_axis;																						//return Major Axes value
	}

	/**
	 * The minor axis or width of this ellipse.
	 */
	// Queries:
	public int minor_axis() {
		return minor_axis;																						//return Minor Axes value
	}

	/**
	 * The area of this ellipse.
	 * @Require major_axis > 0 && minor_axis > 0;
	 * @Ensure  area >= 0;
	 */
	//Calculate area of Ellipse
	public double area() {
		assert major_axis > 0 && minor_axis > 0;																//Precondition Challenge
		return Math.PI * major_axis * minor_axis / 4;															//Calculates the Area of Major and Minor Axes values
	}

	/**
	 * The circumference of this ellipse.
	 * We use the approximation from
	 * http://en.wikipedia.org/wiki/Ellipse
	 * 
	 * @Require  major_axis > 0 && minor_axis > 0 || ( major_axis == minor_axis && major_axis !=0 )|| ( major_axis == minor_axis && major_axis !=1 );
	 * @Ensure  circumference != NaN; 
	 */
	//Calculate circumference of Ellipse 
	public double circumference() {
		assert major_axis >  0 && minor_axis >  0;																//precondition challenge
	    assert major_axis != 0 && minor_axis != 0;																//Precondition Challenge
		assert major_axis != 1 && minor_axis != 1;																//Precondition Challenge
		final double a = major_axis / 2;																		//variable for circumference calculation
		final double b = minor_axis / 2;																		//variable for circumference calculation
		double factor = (a-b)/(a+b);																			//variable for circumference calculation
		factor = 3 * factor * factor;																			//Calculate Factor
		double circumference = Math.PI * (a+b) * (1 + factor/(10 + Math.sqrt(4-factor)) );						//Calculate Circumference
		return circumference;																					//return Circumference
	}

}